/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edi.dao;

import edi.entities.DepUsrDocEntity;

import edi.entities.DepartmentUserEntity;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
@Transactional
public class DepUsrDocDaoImp extends HibernateCrudDao<DepUsrDocEntity> implements DepUsrDocDao {
    
    public DepUsrDocDaoImp() {
	super(DepUsrDocEntity.class);
    }
    
    @Override
    public DepUsrDocEntity findOneByDocId(Long docId){
        return (DepUsrDocEntity)session().getNamedQuery("DepUsrDoc.findByDocId").setLong("dudDocument", docId).uniqueResult();
    }

    @Override
    public List<DepUsrDocEntity> findAllByDocId(Long docId){
        return session().getNamedQuery("DepUsrDoc.findByDocId")
                .setLong("dudDocument", docId).list();
    }


    @Override
    public List<DepUsrDocEntity> findByDepartmentUser(DepartmentUserEntity departmentUserEntity) {
        return session().createQuery("from DepUsrDocEntity where dudDepartmentUser = :depUsr")
                .setEntity("depUsr", departmentUserEntity).list();
    }

    @Override
    public List<DepUsrDocEntity> findByDepartmentUser(List<DepartmentUserEntity> departmentUserEntities) {
        return session().createQuery("from DepUsrDocEntity where dudDepartmentUser in (:depUsr)")
                .setParameterList("depUsr", departmentUserEntities).list();
    }
}
